import 'package:flutter/material.dart';

import '../resources/resources.dart';
import 'my_text.dart';

typedef TtsSpeedItemTapCallback = void Function(int tag);

class SetingItem extends StatefulWidget {
  const SetingItem(
      {Key? key,
      this.onTap,
      required this.title,
      this.tag,
      this.isSelected: false})
      : super(key: key);

  final TtsSpeedItemTapCallback? onTap;
  final String title;
  final int? tag;
  final bool isSelected;

  @override
  _SetingItemState createState() => _SetingItemState();
}

class _SetingItemState extends State<SetingItem> {
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        if (widget.onTap != null) {
          widget.onTap!(widget.tag!);
        }
      },
      child: Container(
        margin: const EdgeInsets.only(left: 20.0),
        padding: const EdgeInsets.fromLTRB(0, 15.0, 15.0, 15.0),
        constraints:
            BoxConstraints(maxHeight: double.infinity, minHeight: 60.0),
        width: double.infinity,
        decoration: BoxDecoration(
            border: Border(
          bottom: Divider.createBorderSide(context, width: 0.6),
        )),
        child: Row(
          //为了数字类文字居中
          //crossAxisAlignment: maxLines == 1 ? CrossAxisAlignment.center : CrossAxisAlignment.start,
          children: <Widget>[
            MyText(
              widget.title,
              size: 16,
              color: Colors.black87,
            ),
            Spacer(),
            AnimatedOpacity(
              opacity: widget.isSelected ? 1.0 : 0.0,
              duration: Duration(milliseconds: 200),
              child: Icon(
                Icons.check_circle,
                color: JmColors.main,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
